<!doctype html>
<html lang="zh-CH">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
    <title>木投网--个人中心--修改密码</title>
    <link rel="stylesheet" href="/resource/css/mt_index.css">
    <link rel="stylesheet" href="/resource/css/mt_user.css">
    <link rel="stylesheet" href="/resource/css/mt_showBo.css">
</head>
<body>
@include("common.shop_user_head")
<div class="user-cont left">
    <div class="user-title">修改密码</div>
    <div class="amend">
            <div class="form-group">
                <label for="">旧密码：</label>
                <input type="password" id="old_password" class="form-control" placeholder="请输入旧密码">
                <i class="i i-pass"></i>
                <span>不能为空</span>
            </div>
            <div class="form-group">
                <label for="">新密码：</label>
                <input type="password" id="new_password" class="form-control" placeholder="请输入新密码">
                <i class="i i-pass"></i>
                <span>不能为空</span>
            </div>
            <div class="form-group">
                <label for="">再次密码：</label>
                <input type="password" id="new_password1" class="form-control" placeholder="请确认新密码">
                <i class="i i-pass"></i>
                <span>两次输入密码不一致</span>
            </div>
            <input type="hidden" id="user_id" value={{$user_id}}>
            <button type="submit" class="btn-login">提交</button>
    </div>
</div>
@include("common.shop_user_foot")
<script src="/resource/js/jquery-1.11.3.min.js"></script>
<script src="/resource/js/mt_index.js"></script>
<script src="/resource/js/mt_showBo.js"></script>  <!-- 提示信息 -->
<script>

//    $('.form-control').blur(function(){
//        if($(this).val()==''){
//            $(this).siblings('span').show().html('不能为空');
//        }else{
//            $(this).siblings('span').hide();
//        }
//    });
    $('#old_password').blur(function(){
        var user_id = $('#user_id').val();
        var old_password = $('#old_password').val();
        var new_password = $('#new_password1').val();

        if($(this).val()==''){
            $(this).siblings('span').show().html('不能为空');
        }else{
            $(this).siblings('span').hide();
            $.ajax({
					url : '/user_password_select',
					type : "POST",
					data : {user_id:user_id,password:old_password},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
                        console.log(json);
						if(json.code == 0){

                            $('#old_password').siblings('span').show().html('原始密码输入错误');
                            return false;
						}
					}
				});
			}
    });
    $('#new_password').blur(function(){
        if($(this).val()==''){
            $(this).siblings('span').show().html('不能为空');
            return false;
        }else{
            $(this).siblings('span').hide();
        }
    });
    $('#new_password1').blur(function(){
        if($(this).val()=='') {
            $(this).siblings('span').show().html('不能为空');
            return false;
        }else{
            $(this).siblings('span').hide();
            var new_password = $('#new_password').val();
            var new_password1 = $('#new_password1').val();
            if(new_password!=new_password1){
                $(this).siblings('span').show().html('两次输入密码不一致');
                return false;

            }
        }
    });
    $('.btn-login').click(function(){
        var user_id = $('#user_id').val();
        var old_password = $('#old_password').val();
        var new_password = $('#new_password1').val();
        if(old_password==''){
            $('#old_password').siblings('span').show().html('不能为空');
            return false;
        }else{
            $('#old_password').siblings('span').hide();
        }
        if(new_password==''){
            $('#new_password').siblings('span').show().html('不能为空');
            return false;
        }else{
            $('#new_password').siblings('span').hide();
        }
        if(new_password1==''){
            $('#new_password1').siblings('span').show().html('不能为空');
            return false;
        }else{
            $('#new_password1').siblings('span').hide();
        }
        $('.form-group span').hide();
        $.ajax({
            url : '/user_password_update',
            type : "POST",
            data : {user_id:user_id,old_password:old_password,new_password:new_password},
            dataType : "json",
            cache:"false",
            timeout:30000,
            success : function(json) {
                console.log(json);
                if(json.code == 1){

                    Showbo.Msg.amend('<img class="left" src="/resource/img/reg_success.png" alt=""><span style="float:left;line-height:70px;">重置成功</span>',function(btn){
                        if (btn == 'yes') {
                            window.location.href = '/login';
                        }else{
                            return false;
                        };
                    },'重新登录');
                    $('#dvMsgBtns input.btn').css({
                        'width':'110px',
                        'margin-left':'95px'
                    });

                }
            }
        });

    });
</script>
</body>
</html>